package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TSup;
import com.ruoyi.system.service.ITSupService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 供应商 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-02-20
 */
@Controller
@RequestMapping("/system/tSup")
public class TSupController extends BaseController
{
    private String prefix = "system/tSup";
	
	@Autowired
	private ITSupService tSupService;
	
	@GetMapping()
	public String tSup()
	{
	    return prefix + "/tSup";
	}
	
	/**
	 * 查询供应商列表
	 */
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TSup tSup)
	{
		startPage();
        List<TSup> list = tSupService.selectTSupList(tSup);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出供应商列表
	 */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TSup tSup)
    {
    	List<TSup> list = tSupService.selectTSupList(tSup);
        ExcelUtil<TSup> util = new ExcelUtil<TSup>(TSup.class);
        return util.exportExcel(list, "tSup");
    }
	
	/**
	 * 新增供应商
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存供应商
	 */
	@Log(title = "供应商", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TSup tSup)
	{		
		return toAjax(tSupService.insertTSup(tSup));
	}

	/**
	 * 修改供应商
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		TSup tSup = tSupService.selectTSupById(id);
		mmap.put("tSup", tSup);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存供应商
	 */
	@Log(title = "供应商", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TSup tSup)
	{		
		return toAjax(tSupService.updateTSup(tSup));
	}
	
	/**
	 * 删除供应商
	 */
	@Log(title = "供应商", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(tSupService.deleteTSupByIds(ids));
	}
	
}
